<!-- 时间范围选择 -->
<template>
	<view class="panel" v-show="visible">
		<view class="container" :style="{'padding-bottom': safeAreaBottom + 'px'}" :class="{'show': isShow}">
			<view class="header">
				<text class="title">选择营业时间</text>
				<button class="close-btn btn-transition-scale9 iconfont" @click="handleClose()">&#xe60d;</button>
			</view>
			<view class="body">
				<view class="tips">
					<text class="label">开始时间</text>
					<text class="label">结束时间</text>
				</view>
				<picker-view :value="value" indicator-style="height: 50px;" class="picker-view">
					<picker-view-column>
						<view class="item" v-for="value in hours" :key="value">{{value}}</view>
					</picker-view-column>
					<picker-view-column>
						<view class="item" v-for="value in minutes" :key="value">{{value}}</view>
					</picker-view-column>
					<picker-view-column>
						<view class="item" v-for="value in hours" :key="value">{{value}}</view>
					</picker-view-column>
					<picker-view-column>
						<view class="item" v-for="value in minutes" :key="value">{{value}}</view>
					</picker-view-column>
				</picker-view>
			</view>
			<view class="footer" :style="{'padding-bottom': safeAreaBottom === 0? '20rpx': '0rpx'}">
				<button class="btn btn-transition-scale95" @click="handleConfirm()">确 认</button>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref, watch } from 'vue';

	const emits = defineEmits(['update:visible']);

	const visible = defineModel('visible');
	const safeAreaBottom = getApp().globalData.safeAreaBottom; // 底部安全区域高度
	const isShow = ref(false);

	watch(() => visible.value, (value) => {
		if (value) {
			setTimeout(() => {
				isShow.value = true;
			}, 20);
		}
	});

	const handleClose = () => {
		isShow.value = false;
		setTimeout(() => {
			emits('update:visible', false);
		}, 300);
	}

	const handleConfirm = () => {
		handleClose();
	}

	const hours = [];
	const minutes = [];
	for (let i = 0; i < 24; i++) {
		hours.push(i < 10 ? '0' + i : i);
	}
	for (let i = 0; i < 60; i++) {
		minutes.push(i < 10 ? '0' + i : i);
	}

	const value = [0, 0, 0, 0]
</script>

<style lang="scss" scoped>
	.panel {
		position: fixed;
		top: 0;
		left: 0;
		z-index: 9999;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.6);
	}

	.container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		background-color: white;
		border-radius: 35rpx 35rpx 0 0;
		padding-top: 50rpx;
		transform: translateY(100%);
		transition: transform 0.3s;

		&.show {
			transform: translateY(0%);
		}

		.header {
			position: relative;
			text-align: center;

			.title {
				font-weight: bold;
				font-size: 36rpx;
				color: #222222;
				font-weight: bold;
			}

			.close-btn {
				position: absolute;
				top: 50%;
				right: 34rpx;
				transform: translateY(-50%);
				font-size: 30rpx;
				color: #999999;
				background-color: transparent;
			}
		}

		.body {
			padding: 20rpx 38rpx 56rpx;
			
			.tips {
				display: flex;
				align-items: center;
				padding: 20rpx 0;
				
				.label {
					flex-grow: 1;
					font-size: 28rpx;
					color: #999999;
					text-align: center;
				}
			}

			.picker-view {
				position: relative;
				width: 100%;
				height: 500rpx;
				
				&::before {
					position: absolute;
					top: 50%;
					left: 25%;
					transform: translate(-50%, -52%);
					display: block;
					content: ':';
					font-size: 28rpx;
					color: #222222;
					line-height: 50px;
				}
				
				&::after {
					position: absolute;
					top: 50%;
					left: 75%;
					transform: translate(-50%, -52%);
					display: block;
					content: ':';
					font-size: 28rpx;
					color: #222222;
					line-height: 50px;
				}
			}

			.item {
				line-height: 50px;
				text-align: center;
			}
		}

		.footer {
			padding: 0 63rpx;

			.btn {
				width: 100%;
				height: 88rpx;
				font-size: 28rpx;
				color: white;
				text-align: center;
				line-height: 88rpx;
				border-radius: 44rpx;
				background-color: #FE3333;
			}
		}
	}
</style>